package cn.itsource.ymcc.controller;

import cn.itsource.ymcc.doc.CourseDoc;
import cn.itsource.ymcc.dto.CourseQueryDto;
import cn.itsource.ymcc.result.JSONResult;
import cn.itsource.ymcc.result.PageList;
import cn.itsource.ymcc.service.ICourseESService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/course")
public class ESCourseController {


    @Autowired
    private ICourseESService courseESService;

    //添加课程
    @RequestMapping(value = "/addCourse",method = RequestMethod.POST)
    public JSONResult addCourse(@RequestBody CourseDoc doc){
        courseESService.save(doc);
        return JSONResult.success();
    }

    //搜索课程
    @RequestMapping(value = "/search",method = RequestMethod.POST)
    public JSONResult searchCourse(@RequestBody CourseQueryDto dto){
        PageList<CourseDoc> pageList = courseESService.searchCourse(dto);
        return JSONResult.success(pageList);
    }
}
